home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Games / Pentominoes 2.0 / Shell ƒ / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-15  |  2.0 KB  |  60 lines  |  [TEXT/MMCC]

  1. #include "error.h"
  2. #include "main.h"
  3. #include "dialog layer.h"
  4. #include "environment.h"
  5. #include "window layer.h"
  6.  
  7. ErrorStateRec        gPendingErrorRec;
  8.  
  9. void FailNilUPP(UniversalProcPtr theUPP)
  10. {
  11.     if (theUPP == nil)
  12.         HandleError(kNoMemory, FALSE, FALSE);
  13. }
  14.  
  15. void HandleError(ErrorTypes resultCode, Boolean isFatal, Boolean isSmall)
  16. /* if we're in the foreground, just get the error string (from the .rsrc file) and
  17.    display the error alert; otherwise, we have to queue it, put up a notification
  18.    (if possible), and wait patiently to come back in the foreground.  (see main.c,
  19.    DispatchEvents(), case osEvt) */
  20. /* All error codes are listed in program globals.h */
  21. {
  22.     Str255            tempStr;
  23.     Handle            myResHand;
  24.     
  25.     /* if there is no error, or the error is that the user cancelled an operation
  26.        in progress, don't display anything; it would only confuse them. */
  27.     if ((resultCode==userCancelErr) || (resultCode==allsWell)) return;
  28.     
  29.     if (gIsInBackground)    /* if program is in background, can't display alert immed. */
  30.     {
  31.         if (gHasNotificationManager)    /* if they don't have notification, f*ck 'em */
  32.         {
  33.             myResHand=GetResource('SICN', 1234);    /* small icon for menu bar flashing */
  34.             gPendingErrorRec.notificationRec.qType=nmType;            /* for more detail on these params, */
  35.             gPendingErrorRec.notificationRec.nmMark=1;                /* see IM Processes, 5-8 */
  36.             gPendingErrorRec.notificationRec.nmIcon=myResHand;
  37.             gPendingErrorRec.notificationRec.nmSound=(Handle)-1L;
  38.             gPendingErrorRec.notificationRec.nmStr=0L;
  39.             gPendingErrorRec.notificationRec.nmResp=0L;
  40.             gPendingErrorRec.notificationRec.nmRefCon=0L;
  41.             NMInstall(&gPendingErrorRec.notificationRec);
  42.         }
  43.         gPendingErrorRec.resultCode=resultCode;                /* remember error code for later */
  44.     }
  45.     else
  46.     {
  47.         GetIndString(tempStr, 129, resultCode);    /* get error string from .rsrc */
  48.         if (isFatal)
  49.             SysBeep(7);
  50.         DisplayTheAlert(kStopAlert, isSmall ? kSmallAlertID : kLargeAlertID, tempStr, "\p", "\p", "\p",
  51.             0L);
  52.         
  53.         if (isFatal)        /* for fatal errors */
  54.         {
  55.             ShutDownEnvironment(FALSE);
  56.             ExitToShell();
  57.         }
  58.     }
  59. }
  60.